package com.yunkeji.api.call.mapper;

import com.yunkeji.api.user.vo.CountVo;
import com.yunkeji.dao.mapper.CallSheetInfoMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;

/** @author 老张 */
public interface ApiCallSheetInfoMapper extends CallSheetInfoMapper {

    /**
     * 累计支付费用
     *
     * @author 老张
     * @param id
     */
    @Update("UPDATE ykj_call_sheet_info SET pay_cost = (pay_cost+call_price) WHERE id =#{id}")
    Integer addPayCost(@Param("id") Long id, @Param("num") BigDecimal num);

    /**
     * 按时间统计
     *
     * @author 老张
     * @param userId
     * @param today
     * @return
     */
    @Select(
            "SELECT "
                    + " SUM( duration )duration , "
                    + " SUM( caller_id != #{uid} ) callSum, "
                    + " SUM( answer_id != #{uid} )  answerSum "
                    + "FROM "
                    + " ykj_call_sheet_info  "
                    + "WHERE "
                    + " call_date=#{date} and "
                    + " duration > 0  "
                    + " AND ( "
                    + " caller_id = #{uid} "
                    + " OR answer_id = #{uid} )")
    CountVo.CountCallData countToday(@Param("uid") Long userId, @Param("date") String today);
}
